package com.servlet;

import com.dao.StudenCla;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/addtest2")
public class AddClass extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            increase(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //增加
    private void increase(HttpServletRequest req, HttpServletResponse resp) throws ServletException, SQLException, IOException {
        Integer id = Integer.parseInt(req.getParameter("id"));
        String name = req.getParameter("name");
        System.out.println(id+name);

        StudenCla studenCla = new StudenCla();
        try {
            studenCla.increase(id,name);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        CheckClass.checkCl(req, resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
